
const mysql=require('mysql2')
 
const {APP_PORT,MYSQL_HOST,MYSQL_PORT,MYSQL_DATABASE,MYSQL_ROOT,MYSQL_PASSWORD}=require('./config')
//注册连接池
const connections=mysql.createPool({
 
   host: MYSQL_HOST,
   port: MYSQL_PORT,
   database: MYSQL_DATABASE,
   user :MYSQL_ROOT,
  password:MYSQL_PASSWORD
})
//判断是否连接
connections.getConnection((err,cnn)=>{
    cnn.connect((err)=>{
        if(err){
            console.log("连接数据库失败")
        }else{
            console.log("连接数据库成功")
        }
    })
})
//返回的应该是promise
module.exports=connections.promise()
